<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""DTD/xhtml1-strict.dtd">
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/c.tld" prefix="c"%>
<%@taglib uri="/WEB-INF/fmt.tld" prefix="fmt"%>
<%@taglib uri="/WEB-INF/el.tld" prefix="el"%>
<%@taglib uri="/WEB-INF/fn.tld" prefix="fn"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		<title></title>
		<c:import url="/includes/css_inc.jsp"/>
		<c:import url="/includes/js_inc.jsp"/>
		<script>
			$(function(){
				$("#btnSave").button({
		            icons: {
		                primary: "ui-icon-disk"
		            }
				}).click(function(){
					if (validateEmpty()){
						$("#isContinue").val("N");
						$("#venderName").removeAttr("disabled");
						$("#venderBankCode").removeAttr("disabled");
						$("#venderAccount").removeAttr("disabled");
						$("#venderAccountName").removeAttr("disabled");
						$("#saveForm").submit();
					}
				});
				$("#btnSaveContinue").button({
		            icons: {
		                primary: "ui-icon-disk"
		            }
				}).click(function(){
					if (validateEmpty()){
						$("#isContinue").val("Y");
						$("#venderName").removeAttr("disabled");
						$("#venderBankCode").removeAttr("disabled");
						$("#venderAccount").removeAttr("disabled");
						$("#venderAccountName").removeAttr("disabled");
						$("#saveForm").submit();
					}
				});
				$("#btnBack").button({
		            icons: {
		                primary: "ui-icon-arrowreturnthick-1-w"
		            }
				}).click(function(){
					$("#job").val("back");
					$("#saveForm").submit();
				});
				$("#venderTypeT").click(function(){
					document.getElementById("venderBankBranchNameSpan").innerHTML = "";
					document.getElementById("venderBankBranchCodeSpan").innerHTML = "";
					document.getElementById("venderAccountSpan").innerHTML = "";
					document.getElementById("venderBankCodeSpan").innerHTML = "";
					document.getElementById("venderAccountNameThSpan").innerHTML = "";
					var dhtml = new DHTML(); 
					dhtml.createElement(document.getElementById("venderAccountSpan"), ["span","id=#venderAccount","class=red"], "*");
					dhtml.createElement(document.getElementById("venderAccountNameThSpan"), ["span","id=#venderAccountNameTh","class=red"], "*");
					dhtml.createElement(document.getElementById("venderBankCodeSpan"), ["span","id=#venderBankCode","class=red"], "*");
					if ($("#venderBankCode").val() != "034" ){
						dhtml.createElement(document.getElementById("venderBankBranchNameSpan"), ["span","id=#venderBankBranchName","class=red"], "*");
						dhtml.createElement(document.getElementById("venderBankBranchCodeSpan"), ["span","id=#venderBankBranchCode","class=red"], "*");				
					}
				});
				$("#venderTypeC").click(function(){
					document.getElementById("venderAccountSpan").innerHTML = "";
					document.getElementById("venderBankCodeSpan").innerHTML = "";
					document.getElementById("venderAccountNameThSpan").innerHTML = "";
					document.getElementById("venderBankBranchNameSpan").innerHTML = "";
					document.getElementById("venderBankBranchCodeSpan").innerHTML = "";
				});
				$("#venderBankCode").change(function(){
					var dhtml = new DHTML(); 
					document.getElementById("venderBankBranchNameSpan").innerHTML = "";
					document.getElementById("venderBankBranchCodeSpan").innerHTML = "";
					if ($("#venderBankCode").val() != "034" && !$("#venderTypeC").is(":checked")) {
						dhtml.createElement(document.getElementById("venderBankBranchNameSpan"), ["span","id=#venderBankBranchName","class=red"], "*");
						dhtml.createElement(document.getElementById("venderBankBranchCodeSpan"), ["span","id=#venderBankBranchCode","class=red"], "*");
					} else {
						document.getElementById("venderBankBranchNameSpan").innerHTML = "";
						document.getElementById("venderBankBranchCodeSpan").innerHTML = "";
					}
				});
				$("#venderBankBranchCode").blur(function(){
					if ($("#venderBankBranchCode").val() != null && $("#venderBankBranchCode").val() != "") {
						var length = $.trim($("#venderBankBranchCode").val()).length;
						var branchCode = $("#venderBankBranchCode").val();
						if(parseFloat(length) < 4){
							for (var i=0;i<(4-parseFloat(length));i++) {
								branchCode = "0"+branchCode;
							}
							$("#venderBankBranchCode").val(branchCode);
						} 
					}
				});
			});
			function checkBankCode(){
				var dhtml = new DHTML(); 
				document.getElementById("venderBankBranchNameSpan").innerHTML = "";
				document.getElementById("venderBankBranchCodeSpan").innerHTML = "";
				if ($("#venderBankCode").val() != "034" && !$("#venderTypeC").is(":checked")) {
					dhtml.createElement(document.getElementById("venderBankBranchNameSpan"), ["span","id=#venderBankBranchName","class=red"], "*");
					dhtml.createElement(document.getElementById("venderBankBranchCodeSpan"), ["span","id=#venderBankBranchCode","class=red"], "*");
				} else {
					document.getElementById("venderBankBranchNameSpan").innerHTML = "";
					document.getElementById("venderBankBranchCodeSpan").innerHTML = "";
				}
			}
		</script>
	</head>
	<body onload="checkBankCode();">
		<c:set var="auth" value="${el:getMapValue(menuAuth, 'ACC60107')}"/>
		<c:import url="/apps/msg.jsp"/>
		<form class="acc67-form" name="saveForm" id="saveForm" action="${pageContext.request.contextPath}/acc6" method="post">
		<input type="hidden" name="app" id="app" value="ACC60107"/>
		<input type="hidden" name="job" id="job" value="${job}"/>
		<input type="hidden" name="isContinue" id="isContinue" value="${isContinue}"/>
		<c:if test="${!empty venderBean && (venderBean.venderType == 'M' || venderBean.venderType == 'A') && !empty venderBean.venderAccount}" var="isDisable"/>
		<c:if test="${job == 'edit' && userInfo.roleId != '1'}" var="isAdmin"/>
		<table width="100%" class="ui-widget ui-widget-content" border="0">
			<tr>
				<th align="left" class="acc67-header ui-widget-header" colspan="2"><b>${screenCode.ACC60107}</b></th>
			</tr>
			<tr>
				<td width="35%" class="bold">จังหวัด : </td>
				<td>
					<c:if test="${userInfo.areaLevel =='3'}">
						<c:forEach var="data" items="${userInfo.listUserProvice}">
							${data.provinceName}
							<input type="hidden" name="provinceId" id="provinceId" value="${data.provinceId}">
						</c:forEach>
					</c:if>
					<c:if test="${userInfo.areaLevel=='1' || userInfo.areaLevel=='2'}">
						<c:if test="${job == 'edit'}">
							${provinceName}
							<input type="hidden" name="provinceId" id="provinceId" value="${provinceId}">
						</c:if>
						<c:if test="${job == 'save'}">
							<select name="provinceId" id="provinceId">
								<option value="">----- เลือก -----</option>
								<c:forEach var="data" items="${userInfo.listUserProvice}">
									<c:if test="${data.provinceId == provinceId}" var="provinceSeleted"/>
									<option value="${data.provinceId}" ${provinceSeleted?'selected':''}>${data.provinceName}</option>
								</c:forEach>
							</select>
							<span id="$provinceId" class="red">*</span>
						</c:if>
					</c:if>
				</td>
			</tr>
			<tr>
				<td class="bold">รหัส : </td>
				<td>
					<c:if test="${!empty venderBean.venderCode}">
						${venderBean.venderCode}
					</c:if>
					<c:if test="${empty venderBean.venderCode}">
						สร้างจากระบบ
					</c:if>
					<input type="hidden" name="venderCode" id="venderCode" value="${venderBean.venderCode}">
				</td>	
			</tr>
			<tr>
				<td class="bold" valign="top">ประเภทคู่สัญญาระดับจังหวัด : </td>
				<td>
					<input type="radio" name="venderType" id="venderTypeT" ${isAdmin ? 'disabled' : ''} value="T" ${venderBean.venderType == 'T' || venderBean.venderType == 'M' ?'checked':''}/> จ่ายโอน
					<input type="radio" name="venderType" id="venderTypeC" ${isAdmin ? 'disabled' : ''} value="C" ${venderBean.venderType == 'C'?'checked':''}/> จ่าย Cheque
					<span id="@venderType" class="red">*</span>
				</td>	
			</tr>
			<tr>
				<td class="bold">ชื่อคู่สัญญาระดับจังหวัด : </td>
				<td>
					<input type="text" name="venderName" id="venderName" ${isDisable?'disabled':''} value="${venderBean.venderName}">
					<span id="#venderName" class="red">*</span>
				</td>
			</tr>
			<tr>
				<td class="bold">ธนาคาร : </td>
				<td>
					<select name="venderBankCode" id="venderBankCode" ${isDisable?'disabled':''}>
						<option value ="">----- เลือก -----</option>
						<option value ="034" selected="selected" >BAAC : ธนาคารเพื่อการเกษตรและสหกรณ์การเกษตร</option>
						<option value ="002" ${venderBean.venderBankCode == '002'?'selected':''}>BBL : ธนาคารกรุงเทพ</option>
						<option value ="004" ${venderBean.venderBankCode == '004'?'selected':''}>KBANK : ธนาคารกสิกรไทย</option>
						<option value ="006" ${venderBean.venderBankCode == '006'?'selected':''}>KTB : ธนาคารกรุงไทย</option>
						<option value ="011" ${venderBean.venderBankCode == '011'?'selected':''}>TMB : ธนาคารทหารไทย</option>
						<option value ="014" ${venderBean.venderBankCode == '014'?'selected':''}>SCB : ธนาคารไทยพาณิชย์</option>
						<option value ="020" ${venderBean.venderBankCode == '020'?'selected':''}>SCBT : ธนาคารสแตนดาร์ดชาร์เตอร์ด</option>
						<option value ="022" ${venderBean.venderBankCode == '022'?'selected':''}>CIMB : ธนาคารซีไอเอ็มบี ไทย</option>
						<option value ="024" ${venderBean.venderBankCode == '024'?'selected':''}>UOB : ธนาคารยูโอบี</option>
						<option value ="025" ${venderBean.venderBankCode == '025'?'selected':''}>AYUD : ธนาคารกรุงศรีอยุธยา</option>
						<option value ="030" ${venderBean.venderBankCode == '030'?'selected':''}>GSBA : ธนาคารออมสิน</option>
						<option value ="033" ${venderBean.venderBankCode == '033'?'selected':''}>GHB : ธนาคารอาคารสงเคราะห์</option>
						<option value ="035" ${venderBean.venderBankCode == '035'?'selected':''}>EXTH : ธนาคารเพื่อการส่งออกและนำเข้าแห่งประเทศไทย</option>
						<option value ="065" ${venderBean.venderBankCode == '065'?'selected':''}>TBNK : ธนาคารธนชาติ</option>
						<option value ="066" ${venderBean.venderBankCode == '066'?'selected':''}>TIBT : ธนาคารอิสลามแห่งประเทศไทย</option>
						<option value ="067" ${venderBean.venderBankCode == '067'?'selected':''}>TISCO : ธนาคารทิสโก้</option>
						<option value ="069" ${venderBean.venderBankCode == '069'?'selected':''}>KK : ธนาคารเกียรตินาคิน</option>
						<option value ="073" ${venderBean.venderBankCode == '073'?'selected':''}>LHB : ธนาคารแลนด์ แอนด์ เฮ้าส์</option>
					</select>
					<span id="venderBankCodeSpan">
						<c:if test="${venderBean.venderType == 'T'}">
							<span id="$venderBankCode" class="red">*</span>
						</c:if>
					</span>
				</td>
			</tr>
			<tr>
				<td class="bold">รหัสสาขาธนาคารคู่สัญญาระดับจังหวัด : </td> 
				<td>
					<input type="text" name="venderBankBranchCode" id="venderBankBranchCode" ${isDisable?'disabled':''} size="5" maxlength="4" onkeypress="return numberOnly(event)" value="${venderBean.venderBankBranchCode}">	
					<span id="venderBankBranchCodeSpan"></span>
				</td> 
			</tr>
			<tr>
				<td class="bold">ชื่อสาขาธนาคารคู่สัญญาระดับจังหวัด : </td> 
				<td>
					<input type="text" name="venderBankBranchName" id="venderBankBranchName" ${isDisable?'disabled':''} value="${venderBean.venderBankBranchName}">
					<span id="venderBankBranchNameSpan"></span>
				</td>
			</tr>
			<tr>
				<td class="bold">เลขที่บัญชี : </td> 
				<td>
					<input type="text" name="venderAccount" id="venderAccount" maxlength="15" ${isDisable?'disabled':''} onkeypress="return numberOnly(event)" value="${fn:trim(venderBean.venderAccount)}">
					<span id="venderAccountSpan">
						<c:if test="${venderBean.venderType == 'T'}">
							<span id="#venderAccount" class="red">*</span>
						</c:if>
					</span>
				</td>
			</tr>
			<tr>
				<td class="bold">ชื่อบัญชีคู่สัญญาระดับจังหวัด ภาษาไทย : </td> 
				<td>
					<input type="text" name="venderAccountNameTh" id="venderAccountNameTh" ${isDisable?'disabled':''} value="${venderBean.venderAccountNameTh}">
					<span id="venderAccountNameThSpan">
						<c:if test="${venderBean.venderType == 'T'}">
							<span id="#venderAccountNameTh" class="red">*</span>
						</c:if>
					</span>
				</td>
			</tr>
			<tr>
				<td class="bold">ที่อยู่ บัญชีคู่สัญญาระดับจังหวัด ภาษาไทย : </td> 
				<td>
					<textarea name="venderAccountAddressTh" id="venderAccountAddressTh" cols="40" ${isDisable?'disabled':''} rows="2">${venderBean.venderAccountAddressTh}</textarea>
				</td>
			</tr>
			<tr>
				<td class="bold">ชื่อบัญชีคู่สัญญาระดับจังหวัด ภาษาอังกฤษ : </td> 
				<td>
					<input type="text" name="venderAccountNameEn" id="venderAccountNameEn" ${isDisable?'disabled':''} value="${venderBean.venderAccountNameEn}">
				</td>
			</tr>
			<tr>
				<td class="bold">ที่อยู่ บัญชีคู่สัญญาระดับจังหวัด ภาษาอังกฤษ : </td> 
				<td>
					<textarea name="venderAccountAddressEn" id="venderAccountAddressEn" ${isDisable?'disabled':''} cols="40" rows="2">${venderBean.venderAccountAddressEn}</textarea>
				</td>
			</tr>
			<tr>
				<td valign="top" class="bold">คำอธิบาย : </td>
				<td>
					<textarea name="venderDesc" id="venderDesc" cols="40" rows="2" ${isDisable?'disabled':''}>${venderBean.venderDesc}</textarea>
				</td>
			</tr>
			<tr>
				<td valign="top" class="bold">สถานะ : </td>
				<td>
					<input type="radio" name="active" id="statusY" value="Y" checked >ใช้งาน 
					<input type="radio" name="active" id="statusN" value="N" ${venderBean.active == 'N' ? 'checked' : ''}>ไม่ใช้งาน
				</td>
			</tr>
			<tr>
				<td align="center" colspan="2">
					<c:if test="${venderBean.venderType == 'M' || venderBean.venderType == 'A'}">
						<c:if test="${!empty venderBean.venderAccount}">
							<c:if test="${fn:contains(auth, 'I') || fn:contains(auth, 'E')}">
								<button type="button" name="btnSave" id="btnSave" class="acc67-button">บันทึกข้อมูล</button>
							</c:if>
							<button type="button" name="btnBack" id="btnBack" class="acc67-button">ย้อนกลับ</button>
						</c:if>
						<c:if test="${empty venderBean.venderAccount}">
							<c:if test="${fn:contains(auth, 'I') || fn:contains(auth, 'E')}">
								<button type="button" name="btnSave" id="btnSave" class="acc67-button">บันทึกข้อมูล</button>
							</c:if>
							<button type="button" name="btnBack" id="btnBack" class="acc67-button">ย้อนกลับ</button>
						</c:if>
					</c:if>
					<c:if test="${venderBean.venderType != 'M' && venderBean.venderType != 'A'}">
						<c:if test="${fn:contains(auth, 'I') || fn:contains(auth, 'E')}">
							<c:if test="${job == 'save'}">
								<button type="button" name="btnSaveContinue" id="btnSaveContinue" class="acc67-button">บันทึกเพิ่มใหม่</button>
							</c:if>
							<button type="button" name="btnSave" id="btnSave" class="acc67-button">บันทึกข้อมูล</button>
						</c:if>
						<button type="button" name="btnBack" id="btnBack" class="acc67-button">ย้อนกลับ</button>
					</c:if>
				</td>
			</tr>
		</form>
	</body>
</html>